<!DOCTYPE html>
<html lang="en">
<head>
    <title>支持考勤列表</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
          name="viewport">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
        [v-cloak] {
            display: none;
        }

        * {
            -webkit-box-sizing: border-box;
            -moz-box-sizing: border-box;
            box-sizing: border-box;
        }

        body {
            margin: 1px;
        }

        table {
            border-spacing: 0;
            border-collapse: collapse;
            display: table;
        }

        table.text-center, table.text-center td, table.text-center th {
            text-align: center;
            font-size: x-small;
        }

        .table-bordered > thead > tr > th, .table-bordered > tbody > tr > th, .table-bordered > tfoot > tr > th, .table-bordered > thead > tr > td, .table-bordered > tbody > tr > td, .table-bordered > tfoot > tr > td {
            border: 1px solid #cbcbcd;
        }

        table th {
            background: #f8f8f8;
        }

        table td {
            padding-top: 5px;
            padding-left: 2px;
            padding-right: 2px;
            padding-bottom: 5px;
        }

        .table-bordered {
            border: 1px solid #cbcbcd;
        }

        .table {
            width: 100%;
            max-width: 100%;
            margin-bottom: 20px;
        }

        .hidden {
            display: none;
        }
        .reginTd {
            max-width: 90px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            position: relative;
            cursor: pointer;
        }

        .div-td-content-more {
            position: absolute;
            height: auto;
            z-index: 999;
            background-color: #d3e8fd;
            padding: 8px 6px;
            font-size: x-small;
            border: 1px solid #e8e8ea;
            display: none;
        }

        .div-td-content-more i {
            width: 15px;
            height: 12px;
            background: url("/dist/img/more-icon.png");
            position: absolute;
            left: 50px;
            top: -12px;
        }
    </style>
</head>
<body>
<section class="content" id="app" style="min-height: 100vh">
    <div class="div-td-content-more"><i></i></div>
    <div class="row">
        <table class="table table-bordered text-center" id="myTable">
            <thead>
            <tr>
                <th style="width: 70px;padding-top: 5px;padding-bottom: 5px">部门/<br/>大区</th>
                <th style="width: 80px;">岗位</th>
                <th style="width: 60px;">姓名</th>
                <template v-if="isDay">
                    <th style="width: 30px;">出勤</th>
                    <th style="width: 60px;">签到时间</th>
                    <th style="width: 180px;">签到地点/请假原因</th>
                </template>
                <template v-else>
                    <th style="width: 55px;">应出勤</th>
                    <th style="width: 55px;">出勤</th>
                    <th style="width: 55px;">请假</th>
                    <th style="width: 55px;">缺勤</th>
                </template>


            </tr>
            </thead>
            <tbody v-cloak>
            <tr v-for="(item,i) in sendData">
                <td :rowspan="item.departNamespan" :class="{hidden: item.departNamedis}">
                    {{item.departName}}
                </td>
                <td :rowspan="item.roleNamespan" :class="{hidden: item.roleNamedis}">
                    {{item.roleName}}
                </td>
                <td style="color:#169BD5;cursor: pointer" @click="lookDetail(item)"
                    v-if="item.name!='空缺'">{{item.name}}
                </td>
                <td v-if="item.name=='空缺'">{{item.name}}</td>
                <template v-if="isDay">
                    <td>
                        <i v-if="item.signState=='0'">
                            <img style="width: 18px;" src="/dist/img/ic_app_right.png">
                        </i>
                        <span v-else-if="item.signState==1">
                            请假
                        </span>
                        <i v-else-if="item.signState==2">
                            <img style="width: 18px;" src="/dist/img/ic_app_worng.png">
                        </i>
                    </td>
                    <td>{{item.createTime}}</td>
                    <template v-if="item.signState==1">
                        <td class="reginTd">{{item.remark}}</td>
                    </template>
                    <template v-else>
                        <td class="reginTd">
                            {{item.address}}
                        </td>
                    </template>
                </template>
                <template v-else>
                    <td>{{item.shouldCount}}</td>
                    <td>{{item.signInCount}}</td>
                    <td>{{item.leaveCount}}</td>
                    <td style="color: red;">{{item.lackCount}}</td>
                </template>
            </tr>
            </tbody>
        </table>
    </div>
    <!-- /.box-body -->
</section>
<!--JQ-->
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<script src="https://file.ggxqce.com/web/vue.min.js"></script>
<script src="/dist/js/oaApp.js"></script>
<script type="text/javascript">
    $(function () {
        $("body").on("click",".reginTd",function(e) {
            var text =$(this).text();
            if(text != "") {
                text="<i></i>"+text;
                $(".div-td-content-more").html(text).css({
                    "width": $(this).outerWidth() + "px",
                    "left": $(this).offset().left,
                    "top": ($(this).offset().top + $(this).outerHeight()) + "px"
                }).show();
                e.stopPropagation();
            }
        });
        $("body").on("click",".div-td-content-more",function (e) {
            e.stopPropagation();
        });
        $("body").on("click",function () {
            $(".div-td-content-more").hide();
        });
    });

</script>
<script type="text/javascript">
    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
        var r = window.location.search.substr(1).match(reg);  //匹配目标参数
        if (r != null) return unescape(r[2]);
        return null; //返回参数值
    }

    function isDay(time) {
        //2018-01-01
        if (time.length > 8) {
            return true
        } else {
            return false
        }
    }

    var app = new Vue({
        el: '#app',
        data: {
            currentUserId: getUrlParam('currentUserId'),
            dateTime: getUrlParam('dateTime'),
            sendData: [],
            userId: getUrlParam('userId'),
            isDay: isDay(getUrlParam('dateTime'))
        },
        methods: {
            lookDetail: function (item) {
                prompt(JSON.stringify(item))
            },
            tablesMergeCell: function (list) {
                for (field in list[0]) {
                    var k = 0;
                    while (k < list.length) {
                        list[k][field + 'span'] = 1;
                        list[k][field + 'dis'] = false;
                        for (var i = k + 1; i <= list.length - 1; i++) {
                            if (list[k][field] == list[i][field] && list[k][field] != '') {
                                list[k][field + 'span']++;
                                list[k][field + 'dis'] = false;
                                list[i][field + 'span'] = 1;
                                list[i][field + 'dis'] = true;
                            } else {
                                break;
                            }
                        }
                        k = i;
                    }
                }
                return list;
            },
            getList: function () {
                var that = this;
                var data = {
                    userId: that.userId,
                    isToday: that.isDay ? "1" : "0",
                    signInMonth: that.dateTime
                }
                //表格
                $.ajax({
                    url: server.ip + urlConfig.system.signIn.getSignInSupportRegionList,
                    contentType: 'application/json;charset=utf-8',
                    type: "POST",
                    data: JSON.stringify(data),
                    success: function (r) {
                        var res = JSON.parse(r)
                        that.sendData = that.tablesMergeCell(res.data.sendData);
                    },
                    error: function (e) {
                        alert(e.responseText)
                    }
                });

            },
        },
        mounted: function () {
            this.getList();
        }

    });
</script>

</body>
</html>